/**
 * Created with IntelliJ IDEA.
 * User: zzl
 * Date: 12-11-23
 * To change this template use File | Settings | File Templates.
 */
if (!window.console) {
    console = {
        log: function (msg) {
            if('log' in window.external) {
                window.external.log(msg);
            }
        }
    }
}
if (!('assert' in console)) {
    console.assert = function (expr, msg) {
        if (!expr) {
            throw new Error(msg || 'assertion failed');
        }
    };
}

var host = {

    isHosted: function () {
        if ('isHosted' in window.external) {
            return window.external.isHosted();
        }
        return false;
    },

    NotifyChange: function () {
        if ('NotifyChange' in window.external) {
            window.external.NotifyChange();
        }
    },

    NotifyUIUpdate: function() {
        if('NotifyUIUpdate' in window.external) {
            window.external.NotifyUIUpdate();
        }
    },

    buildList: function () {
        if ('buildList' in window.external) {
            return window.external.buildList();
        }
        else {
            var $tblTestData = $('#tableTestData');
            if($tblTestData.length) {
                return $tblTestData.children('tbody').html();
            }
            else {
                return '';
            }
        }
    },

    isDueVisible: function () {
        if ('isDueVisible' in window.external) {
            return window.external.isDueVisible();
        }
        return false;
        return true;
    },

    isProgressVisible: function () {
        if ('isProgressVisible' in window.external) {
            return window.external.isProgressVisible();
        }
        else {
            return false;
//            return true;
        }
    },

    isDescVisible: function () {
        if ('isDescVisible' in window.external) {
            return window.external.isDescVisible();
        }
        else {
//            return false;
            return true;
        }
    },

    getColWidths: function () {
        if ('getColWidths' in window.external) {
            var colWidths = window.external.getColWidths();
            colWidths = JSON.parse(colWidths);
            return colWidths;
        }
        else {
            return [0.54, 0, 0, 0.46];
        }
    },


    setupReminder: function (reminders) {
        if ('setupReminder' in window.external) {
            var resultReminders = window.external.setupReminder(reminders);
            window.setupReminderCallback(resultReminders)
        }
        else {
            window.currentReminders = reminders;
            var win = window.open('reminder.html', 'reminder_config', 'width=520,height=320');
        }
    },

    sleep: function (millis) {
        if ('sleep' in window.external) {
            window.external.sleep(millis);
        }
        else {

        }
    },

    NotifyDocReady: function () {
        if ('NotifyDocReady' in window.external) {
            window.external.NotifyDocReady();
        }
    },

    NotifyActiveTodoChanged: function() {
        if ('NotifyActiveTodoChanged' in window.external) {
            window.external.NotifyActiveTodoChanged();
        }
    },

    isDoneItemsVisible: function () {
        if ('isDoneItemsVisible' in window.external) {
            return window.external.isDoneItemsVisible();
        }
        else {
            return true;
        }
    },

    save: function () {
        if ('save' in window.external) {
            return window.external.save();
        }
        else {
            alert('save..');
        }
    },

    saveAndQuit: function () {
        if ('saveAndQuit' in window.external) {
            return window.external.saveAndQuit();
        }
        else {
            alert('saveAndQuit..');
        }
    },

    quit: function () {
        if ('quit' in window.external) {
            return window.external.quit();
        }
        else {
            alert('quit..');
        }
    },

    isGridLineVisible: function() {
        if ('isGridLineVisible' in window.external) {
            return window.external.isGridLineVisible();
        }
//        return false;
        return true;
    },

    isTreeLineVisible: function() {
        if ('isTreeLineVisible' in window.external) {
            return window.external.isTreeLineVisible();
        }
        return true;
    },

    isHeaderVisible: function() {
        if ('isHeaderVisible' in window.external) {
            return window.external.isHeaderVisible();
        }
//        return false;
        return true;
    },

    isTopDownMode: function() {
        if ('isTopDownMode' in window.external) {
            return window.external.isTopDownMode();
        }
        return false;
    },

    getTheme: function() {
        if ('GetThemeName' in window.external) {
            return window.external.GetThemeName();
        }
//        return 'green';
        return null;
    },

    showContextMenu: function(x, y) {
        if('ShowContextMenu' in window.external) {
            return window.external.ShowContextMenu(x, y);
        }
        return false;
    },

    getLocalizedStrings: function() {
        if('GetLocalizedStrings' in window.external) {
            var s = window.external.GetLocalizedStrings();
            if(!s) {
                return null;
            }
            return JSON.parse(s);
        }
        return null;
    },

    placeHolder: null
};
